<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<script type="text/javascript">
function cancelReservation(reservationId) {
	var result = confirm("Are you sure you want to cancel this reservation?");
	if (result == true) {			
		window.location.href = '<c:url value="/spring/myaccount/cancelFlight"/>?reservationId=' + reservationId;
	}	
}
</script>

<div id="messages">
	<form:errors path="customer.*" cssClass="errors" />
</div>

<div class="section">
<h3>My Reservations</h3>


<br/><br/>
<h6>${currentUser.lastName}, these are your reservations: </h6>


<br/><br/>

<c:if test="${not empty currentUser.reservationCollection}">

	<table class="summary">
		<thead>
			<tr>
				<th>Number</th>
				<th>Depart City</th>
				<th>Depart Date</th>
				<th>Dest. City</th>
				<th>Return Date</th>
				<!-- 
				<th>Purchase Date</th>
				 -->
				<th>Payment Type</th>
				<th>Price Paid</th>
				
											
				<th>Cancel Flight</th>
				<th>Reserve Seats</th>
				
				
				
			</tr>
		</thead>
		<tbody>
			<c:forEach var="reservation" items="${currentUser.reservationCollection}">
			<tr>			
				<td>${reservation.number}</td>
				<td>${reservation.departureFlight.departingCity.name}</td>
				<td><fmt:formatDate value="${reservation.departureFlight.departureDate}" dateStyle="short"/></td>
				<td>${reservation.departureFlight.destinationCity.name}</td>				
				<td><fmt:formatDate value="${reservation.returnFlight.departureDate}" dateStyle="short"/></td>
				<!-- 
				<td><fmt:formatDate value="${reservation.purchaseDate}" dateStyle="short"/></td>
				 -->
				<td>${reservation.paymentType}</td>				
				<td>U$ <fmt:formatNumber value="${reservation.price}" minFractionDigits="2" maxFractionDigits="2"/></td>
								
				<td>
				<c:if test="${! reservation.old}"> 
				<a href="javascript:cancelReservation( ${reservation.id})">Cancel</a>
				</c:if> 
				</td>
												
				<td>
				<c:if test="${! reservation.old}">
				 <a href='<c:url value="/spring/myaccount/reserveSeats"/>?reservationId=${reservation.id}'>Reserve</a>
				 </c:if> 
				 </td>
								
								
			</tr>
			</c:forEach>
		</tbody>
	</table>

</c:if>


<c:if test="${empty currentUser.reservationCollection}">
You don't have any reservation.
</c:if>


<br/><br/><br/><br/>
<a href="<c:url value="/spring/myaccount/index" />">Go back to My Account Menu</a>



</div>